import { $tip } from '@/base/util/ui';
import { request as $http } from '@/base/util/request';

/**
 * 通过uri读取Rss最新信息
 * @param {*} param 
 * @returns 
 */
export function readRssOne(param) {
    return new Promise((resolve, reject) => {
        $http.postForm('rss.readOne', param).then(res => {
            if (res.code === 0) {
                resolve(res.data)
            } else {
                $tip.error(res.msg)
            }
        }).catch(res=>{
            reject(res)
            $tip.error(res)
        })
    })

}

/**
 * 增加订阅
 * @param {*} param 
 * @returns 
 */
export function addFollow(param) {
    return new Promise((resolve, reject) => {
        $http.postJson('rss.addFollow', param).then(res => {
            if (res.code === 0) {
                resolve(true)
            } else {
                resolve(false)
                $tip.error(res.msg)
            }
        }).catch(res=>{
            reject(res)
            $tip.error(res)
        })
    })

}

/**
 * 查询订阅
 * @param {*} param 
 * @returns 
 */
export function queryFollow(param) {
    return new Promise((resolve, reject) => {
        $http.postJson('rss.queryFollow', param).then(res => {
            if (res.code === 0) {
                resolve(res.data)
            } else {
                $tip.error(res.msg)
            }
        }).catch(res=>{
            reject(res)
            $tip.error(res)
        })
    })

}


/**
 * 通过数据库读取Rss最新信息
 * @param {*} param 
 * @returns 
 */
export function readHis(param) {
    return new Promise((resolve, reject) => {
        $http.postForm('rss.readHis', param).then(res => {
            if (res.code === 0) {
                resolve(res.data)
            } else {
                $tip.error(res.msg)
            }
        }).catch(res=>{
            reject(res)
            $tip.error(res)
        })
    })
}

/**
 * 读取Rss的最新数据并且增量入库
 * @param {*} param 
 * @returns 
 */
export function addFetch(param) {
    return new Promise((resolve, reject) => {
        $http.postForm('rss.addFetch', param).then(res => {
            if (res.code === 0) {
                resolve(true)
            } else {
                $tip.error(res.msg)
            }
        }).catch(res=>{
            reject(res)
            $tip.error(res)
        })
    })
}

/**
 * 更新Rss订阅信息
 * @param {*} param 
 * @returns 
 */
export function updateRss(param) {
    return new Promise((resolve, reject) => {
        $http.postJson('rss.updateRss', param).then(res => {
            if (res.code === 0) {
                resolve(true)
            } else {
                $tip.error(res.msg)
            }
        }).catch(res=>{
            reject(res)
            $tip.error(res)
        })
    })
}

/**
 * 更新Rss订阅
 * @param {*} param 
 * @returns 
 */
export function editFollow(param) {
    return new Promise((resolve, reject) => {
        $http.postJson('rss.editFollow', param).then(res => {
            if (res.code === 0) {
                resolve(true)
            } else {
                $tip.error(res.msg)
            }
        }).catch(res=>{
            reject(res)
            $tip.error(res)
        })
    })
}
/**
 * 删除Rss订阅
 * @param {*} param 
 * @returns 
 */
export function delFollow(param) {
    return new Promise((resolve, reject) => {
        $http.postForm('rss.delFollow', param).then(res => {
            if (res.code === 0) {
                resolve(true)
            } else {
                $tip.error(res.msg)
            }
        }).catch(res=>{
            reject(res)
            $tip.error(res)
        })
    })
}